<template>
	<view class="zh-u-select-btn-group">
		<view class="title" v-if="props.title">
			<text>{{ props.title }}</text>
		</view>
		<view class="content display-flex align-center flex-wrap" v-if="props.list && props.list.length > 0">
			<template v-for="(item, index) in props.list" :key="item.id">
				<!-- <select-btn class="item" :value="item" :active="props.active == index" @click="selectBtn"></select-btn> -->
				<view class="item" :class="{active:item.active === true}" @click="onClick({index:index,...item})">
					<image src="@/static/icons/selected_icon.png" class="selected-icon" v-show="item.active === true"/>
					<text>{{ item.name }}</text>
				</view>
			</template>
		</view>
		<slot v-else></slot>
	</view>
</template>

<script setup lang="ts">
	const props = defineProps<{
		title?:string
		list:any
	}>()
	
	const emit = defineEmits(['click'])
	
	// const selectBtn = (item:any) => {
	// 	emit('click',item)
	// }
	
	const onClick = (data:any) => {
		emit('click', data)
	}
</script>

<style lang="scss" scoped>
	.zh-u-select-btn-group {
		margin-top:30rpx;
		.title {
			font-size: 30rpx;
			font-weight: bold;
		}
		.content {
			.item {
				margin:26rpx 20rpx 0 0;
				min-width: 140rpx;
				padding:0 10rpx;
				height: 60rpx;
				line-height: 60rpx;
				background-color: #F7F7F7;
				border-radius: 10rpx;
				text-align: center;
				position:relative;
				color:#666;
				.selected-icon {
					width: 28rpx;
					height: 28rpx;
					position:absolute;
					bottom: -14rpx;
					right: -14rpx;
				}
				text {
					font-size: 24rpx;
					white-space:nowrap;
				}
				&.active {
					color:$uni-color-primary;
					background-color: #EAF4FF;
				}
			}
		}
	}
</style>